<?php
/**
 * 产品主表
 * @author 陈德本
 *
 */
class productDao extends commonDao{

    public $table_name = 'product';
    
    protected $fields = "id,pid,seo_title,title,model,price,thumb,desc,content,has_attr,is_recommand,add_time";
    
    /**
     * 分页获取
     */
    public function getPro($pid, $num = 20, $offset = 0, $id_key = 'id', $sort = 'DESC') {
        $pid=intval($pid);
        $id_key = ! empty($this->idKey) && $id_key == 'id' ? $this->idKey : $id_key;
        $sql="SELECT a.*,b.pid as bpid FROM product AS a LEFT JOIN pro_cat AS b ON a.pid=b.id WHERE a.pid=$pid OR b.pid=$pid ORDER BY a.id $sort LIMIT $offset,$num ";
        $result = $this->getDb()->get_all_sql($sql);
        $sql="SELECT count(*) as num FROM product AS a LEFT JOIN pro_cat AS b ON a.pid=b.id WHERE a.pid=$pid OR b.pid=$pid ORDER BY a.id $sort";
        $count=$this->getDb()->get_one_sql($sql);
        return array($result,$count['num']);
    }
    
}